package cn.mythreadtest.test7;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;

public class MyCallable implements Callable<Integer>{
    List<Integer> list;
    public MyCallable(List<Integer> list){
        this.list = list;
    }
    @Override
    public Integer call() throws Exception {
        List<Integer> boxList = new ArrayList<>();
        while (true){
            synchronized (MyCallable.class){
                if(list.isEmpty()){
                    break;
                }else{
                    Collections.shuffle(list);
                    Integer prize = list.remove(0);
                    boxList.add(prize);
                }
            }
        }
        if (boxList.isEmpty()){
            return null;
        }
        return Collections.max(boxList);
    }
}
